using System;
using System.Collections.Generic;
using System.Text;

using Northwind.Domain.Entities;
using NUnit.Framework;

namespace Northwind.Domain.Tests.Custom
{
    [TestFixture]
    public class TransactionFixture
    {
        [Test]
        public void VerifyRollback()
        {
            Awaken.Framework.Gateway.BeginTransaction(typeof(Category));

            string categoryName = "<category-name>";
            string territoryDesc = "<territory-desc>";

            Category category = new Category();
            category.CategoryName = categoryName;
            category.Save();

            Territory territory = new Territory();
            territory.TerritoryID = "<sample-id>";
            territory.TerritoryDescription = territoryDesc;
            territory.RegionID = ((Region)Region.Broker.GetAll()[0]).RegionID;
            territory.Save();

            Category secondCategory = Category.Broker.GetByID(category.CategoryID);
            Assert.AreEqual(categoryName, secondCategory.CategoryName, "CategoryNames should be equal");

            Territory secondTerritory = Territory.Broker.GetByID(territory.TerritoryID);
            Assert.AreEqual(territoryDesc, secondTerritory.TerritoryDescription, "TerritoryDescriptions names should be equal");

            Awaken.Framework.Gateway.RollbackTransaction(typeof(Category));

            Category thirdCategory = Category.Broker.GetByID(category.CategoryID);
            Assert.IsNull(thirdCategory, "Category should not exist.");

            Territory thirdTerritory = Territory.Broker.GetByID(territory.TerritoryID);
            Assert.IsNull(thirdTerritory, "Territory should not exist.");

        }
    }
}
